<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function() {
            var a = {
                age: 12
            };
            var b = a;
            a = {
                name: 'bob',
                age: 13
            };
            b.age = 14;
            console.log(b.age, a.name, a.age); // 14 bob 13
            function fn2(obj) {
                obj = {
                    age: 15
                };
            }
            fn2(a);
            console.log(a.age); // 13

            function Person(color) {
                console.log(this); //输出语句1 
                this.color = color;
                this.getColor = function() {
                    console.log(this); //输出语句2
                    return this.color;
                };
                this.setColor = function() {
                    console.log(this); //输出语句3
                    this.color = color;
                };
            };
            Person("red"); // this是window 执行输出语句1

            var p = new Person("yello"); // this是p 执行输出语句1

            p.getColor(); // this是p 执行输出语句2
            var obj = {};
            p.setColor.call(obj, "black"); // this是obj 

            var test = p.setColor;
            test(); // this是window 因为是直接调用

            function fun1() {
                function fun2() {
                    console.log(this);
                }
                fun2(); // this是window
            }

            console.log(Object instanceof Function); // true
            console.log(Function instanceof Object); // true
            console.log(Function instanceof Function); // true
            console.log(Object instanceof Object); // true

            function Fun() {

            }
            console.log(Object instanceof Fun); // false

            function A() {

            }
            A.prototype.n = 1;
            var b = new A();

            A.prototype = {
                n: 2,
                m: 3
            }

            var c = new A();
            console.log(b.n, b.m, c.n, c.m) // 1 undefined 2 3

            function F() {

            }
            // 在Object的添加原型方法a
            Object.prototype.a = function() {
                    console.log('a()');
                }
                // 在Function
            Function.prototype.b = function() {
                console.log('b()');
            }
            var f = new F();
            f.a();
            //f.b(); //  f.b is not a function
            F.a();
            F.b();

            var x = 3;

            function fn() {
                console.log(x); // undefined 
                var x = 4;
            }
            fn()

            console.log(b); // 能访问 变量提升 b = undefined 
            fn2(); // 能调用 函数提升
            // fn3(); // 不能调用 变量提升 fn3 = undefined

            var b = 3;

            function fn2() {
                console.log('fn2');
            }
            var fn3 = function() {
                console.log('fn3');
            }
            console.log('分割线-------------')
            var a1 = 3;

            function a2() {
                console.log('a2()');
            }
            console.log(a1); // 3
            console.log('分割线-------------')

            function fn(a1) {
                console.log(a1); // 2
                console.log(a2); // undefined
                a3(); // a3()
                console.log(this); // window
                console.log(arguments) // 伪数组[2,3]
                var a2 = 3;

                function a3() {
                    console.log('a3()');
                }
            }
            fn(2, 3);
            console.log('分割线-------------')
            var q = 10;
            var bar = function(x) {
                var p = 5;
                foo(x + p); // foo(15)
            }
            var foo = function(y) {
                var s = 5;
                console.log(q + s + y); // 30
            }
            bar(10)
            console.log('分割线-------------')
            console.log('global begin ' + i);
            var i = 1;
            func(1);

            function func(i) {
                if (i === 4) {
                    return;
                }
                console.log('foo begin ' + i);
                func(i + 1);
                console.log('foo end ' + i);
            }
            console.log('global end ' + i);
            console.log('分割线-------------')

            function varibale() {};
            var varibale;
            console.log(typeof varibale)
            console.log('分割线-------------')
            if (!(nb in window)) {
                var nb = 100;
            }
            console.log(nb); // undefined
            console.log('分割线-------------')
            var c = 1

            function c(c) {
                console.log(c);
            }
            // c(2); // c不是函数 报错

        }
    </script>
</head>

<body>

</body>

</html>